package Demo2_23;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User：Lenovo
 * Date:2025-02-23
 * Time:21:56
 */
import java.util.HashSet;
import java.util.Set;

public class SetTraversal {
    public static void main(String[] args) {
        Set<Integer> numbers = new HashSet<>();
        numbers.add(1);
        numbers.add(2);
        numbers.add(3);

        // 使用 for-each 循环遍历 Set
        for (int num : numbers) {
            System.out.print(num + " ");
        }

        System.out.println();

        // 使用 forEach 方法遍历 Set
        numbers.forEach(num -> System.out.print(num + " "));
    }
}
